<script setup>
import { useAddEditHook } from '@/hooks/crud/index.js'
import { useColumnsDict, useCommonConfig } from './hook.js'
import { useFormConfigHook } from '@/hooks/usePlusConfigHook.js'
const { proxy,  primaryKey,apiFn, moduleName } = useCommonConfig()
const emit = defineEmits(['refreshList'])

// 表单初始化数据
const initForm = {
  postId: undefined,
  postCode: undefined,
  postName: undefined,
  postSort: 0,
  status: "0",
  remark: undefined
}
const rules = {
  postName: [{ required: true, message: "岗位名称不能为空", trigger: "blur" }],
  postCode: [{ required: true, message: "岗位编码不能为空", trigger: "blur" }],
  postSort: [{ required: true, message: "岗位顺序不能为空", trigger: "blur" }],
}

// 钩子函数
const handlerConfig = {
  beforeInfoFn: (reqData) => {
    return reqData[[primaryKey]]
  },
  afterInfoFn: (resData) => {
    return resData
  },
  beforeSubmitFn: (reqData) => {
    return reqData
  },
  afterSubmitFn: (resData) => {
    emit('refreshList')
    return resData
  },
  beforeCloseFn: () => true,
  afterCloseFn: () => {}
}

const { gOpen, gAllExposeOption,gVisible,gFormInstance,gFormData, gIsEdit  } = useAddEditHook({
  moduleName,
  primaryKey,
  initForm,
  rules,
  apiFnConfig:apiFn.apiFnConfig,
  handlerConfig
})

const { gDialogConfig,  gFormConfig} = useFormConfigHook(gAllExposeOption,{
  dialogConfig:{
  },
  formConfig:{
  }
});
const {  dictData,  columns, } = useColumnsDict(true,gFormData);
// 暴露
defineExpose({ gOpen })
</script>
<template>
  <PlusDialog v-model="gVisible" v-bind="gDialogConfig">
    <PlusForm ref="gFormInstance" v-model="gFormData" :columns="columns" v-bind="gFormConfig">
    </PlusForm>
  </PlusDialog>
</template>
<style lang="scss" scoped></style>
